import 'package:flutter/material.dart';

class TagInfo {
  final String text;
  final Color color;

  const TagInfo({required this.text, required this.color});
}

class Tag extends StatelessWidget {
  static const Map<int, TagInfo> tagInfo = {
    1: TagInfo(text: "简单", color: Color(0xff49b68e)),
    2: TagInfo(text: "简单", color: Color(0xff49b68e)),
    3: TagInfo(text: "一般", color: Color(0xfff5a623)),
    4: TagInfo(text: "一般", color: Color(0xfff5a623)),
    5: TagInfo(text: "困难", color: Color(0xffd0021b)),
  };

  final String? text;
  final int? difficulty;
  final Color? color;

  const Tag({super.key, this.text, this.difficulty, this.color}) : assert(difficulty != null || text != null || color != null, "At least one of difficulty, text, or color must be provided");

  @override
  Widget build(BuildContext context) {
    // 获取默认的文字和颜色（如果有 difficulty）
    final TagInfo? info = difficulty != null ? tagInfo[difficulty] : null;
    final String displayText = text ?? info?.text ?? "未知";
    final Color displayColor = color ?? info?.color ?? const Color.fromARGB(255, 245, 167, 255);

    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 3),
      decoration: BoxDecoration(
        color: displayColor.withOpacity(0.2), // 使用颜色的浅色背景
        borderRadius: BorderRadius.circular(4), // 设置圆角
      ),
      child: Text(
        displayText,
        style: TextStyle(
          color: displayColor, // 文本颜色和 Tag 的主色一致
          fontSize: 10,
        ),
      ),
    );
  }
}
